﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="mtamajpaevik_paevik", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(MtamajpaevikPaevik))]
    public class MtamajpaevikPaevikSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IMtamajpaevikPaevik clazz;
        
        public MtamajpaevikPaevikSerializer(IMtamajpaevikPaevik clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("rea_id");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.ReaId))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("piirk");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.Piirk))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("ark");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.Ark))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("maj_aasta");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.MajAasta))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("maj_aastalopp");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.MajAastalopp))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("kontr_olek");
            if (clazz.KontrOlek!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KontrOlek))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : KontrOlek");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("oleku_muutm_kpv");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.OlekuMuutmKpv))).ToString());
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="rea_id") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtamajpaevik_paevik>rea_id");
                }
                clazz.ReaId = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("rea_id")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtamajpaevik_paevik>rea_id", Reader.LocalName);
            }
            if (Reader.LocalName=="piirk") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtamajpaevik_paevik>piirk");
                }
                clazz.Piirk = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("piirk")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtamajpaevik_paevik>piirk", Reader.LocalName);
            }
            if (Reader.LocalName=="ark") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtamajpaevik_paevik>ark");
                }
                clazz.Ark = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("ark")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtamajpaevik_paevik>ark", Reader.LocalName);
            }
            if (Reader.LocalName=="maj_aasta") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtamajpaevik_paevik>maj_aasta");
                }
                clazz.MajAasta = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("maj_aasta")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtamajpaevik_paevik>maj_aasta", Reader.LocalName);
            }
            if (Reader.LocalName=="maj_aastalopp") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtamajpaevik_paevik>maj_aastalopp");
                }
                clazz.MajAastalopp = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("maj_aastalopp")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtamajpaevik_paevik>maj_aastalopp", Reader.LocalName);
            }
            if (Reader.LocalName=="kontr_olek") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtamajpaevik_paevik>kontr_olek");
                }
                clazz.KontrOlek = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kontr_olek")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtamajpaevik_paevik>kontr_olek", Reader.LocalName);
            }
            if (Reader.LocalName=="oleku_muutm_kpv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtamajpaevik_paevik>oleku_muutm_kpv");
                }
                clazz.OlekuMuutmKpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("oleku_muutm_kpv")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtamajpaevik_paevik>oleku_muutm_kpv", Reader.LocalName);
            }
        }
    }
}
